/*********************************************************************************
 *      Copyright:  (C) 2025 chenhongyu IOT STUDY
 *                  All rights reserved.
 *
 *       Filename:  main.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(15/07/25)
 *         Author:  chenhongyu <chenhongyu0822@163.com>
 *      ChangeLog:  1, Release initial version on "15/07/25 22:08:41"
 *                 
 ********************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <dbus/dbus.h>
#include <stdbool.h>
#include <stdint.h>
#include <pthread.h>
#include <syslog.h>

#include "bluez.h"
#include "mqtt.h"
#include "main.h"


int main() 
{
	bled_t                        *ctx=NULL;
	pthread_t                     tid_bt, tid_mqtt;


	if (daemon(0, 0) < 0)
    {
        perror("daemon");
        exit(EXIT_FAILURE);
    }

	ctx=calloc(1, sizeof(bled_t));
	
	openlog("ble_daemon", LOG_CONS | LOG_PID, 0);
	syslog(LOG_NOTICE, "ble_daemon started successfully!\n");	
	
	pthread_create(&tid_bt, NULL, bluetooth_thread, ctx);
	pthread_create(&tid_mqtt, NULL, mqtt_thread, ctx);

	pthread_join(tid_bt, NULL);
	pthread_join(tid_mqtt, NULL);
    
	while (1) 
	{
    	sleep(1);	
    }

	mqtt_cleanup();
	free(ctx);
    return 0;
}


